<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>授权</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/static/css/oksub.css">
	<script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
	<link rel="stylesheet" href="/static/lib/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<style>
		.layui-upload-list img{
			height:100px;
			width:100px;
		}
	</style>
</head>
<body>
<div class="ok-body">
	<form method="post" name="myForm" id="myForm" action="" class="layui-form layui-form-pane ok-form">
        <input type="hidden" name="id" value="{$id}">
		<ul id="treeDemo" class="box box-body ztree"></ul>
        <div class="layui-form-item">
        	<div class="layui-input-block">
        		<button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
        	</div>
        </div>
    </form>
</div>

<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<!-- zTree 树节点组件 -->
<script src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/lib/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/static/lib/zTree/js/jquery.ztree.excheck.js"></script>

<!--内容结束-->
<SCRIPT type="text/javascript">
		<!--
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		var zNodes =[
			{volist name='list' id='list'}
    			{ id:{$list.id}, pId:{$list.pid}, name:"{$list.title}",checked:{$list.checked?'true':'false'}, open:true},
    		{/volist}
		];

		var code;

		function setCheck() {
			 var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        	zTree.setting.check.chkboxType = { "Y":"ps", "N":"s"}; //勾选 checkbox 对于父子节点的关联关系。默认值：{ "Y": "ps", "N": "ps" }
		}
		function showCode(str) {
			if (!code) code = $("#code");
			code.empty();
			code.append("<li>"+str+"</li>");
		}

		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			setCheck();
			$("#py").bind("change", setCheck);
			$("#sy").bind("change", setCheck);
			$("#pn").bind("change", setCheck);
			$("#sn").bind("change", setCheck);
		});
		//-->

   

</SCRIPT>

<script>
	
	layui.use(["element", "form", "laydate", "okLayer", "okUtils"], function () {
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;

		okLoading.close();

		//laydate.render({elem: "#birthday", type: "datetime"});

		form.verify({
			
		});

		form.on("submit(add)", function (data) {
			
			var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
			    nodes=treeObj.getCheckedNodes(true),
			    v="";
			for(var i=0;i<nodes.length;i++){
			    v+=nodes[i].id + ",";
			}
			var id = $('input[name=id]').val();
			
			okUtils.ajax("{:url('auth')}", "post",{id:id,rules:v}, true).done(function (response) {
				//console.log(response);
				if(response.code==1){
					okLayer.greenTickMsg("授权成功", function () {
						parent.layer.close(parent.layer.getFrameIndex(window.name));
					});
				}else{
					okLayer.greenTickMsg(response.msg, function () {
				        
				    })
				}
				
			}).fail(function (error) {
				console.log(error)
			});
			return false;
		});
	});
</script>


</body>
</html>
